namespace AdminApiTemplate.Common.Helpers
{
    public class CollectionHelper
    {
        /// <summary>
        /// 获取分组
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="items"></param>
        /// <param name="capacity"></param>
        /// <returns></returns>
        public static Dictionary<int, List<T>> GetGroups<T>(List<T> items, int capacity)
        {
            var dict = new Dictionary<int, List<T>>();
            var times = (items.Count / capacity) + 1;
            for (var i = 0; i < times; i++)
            {
                dict[i] = new List<T>();
            }

            for (var i = 0; i < items.Count; i++)
            {
                var key = i / capacity;
                dict[key].Add(items[i]);
            }

            return dict;
        }
    }
}
